import type { UserConfig,ConfigEnv} from 'vite'
import { loadEnv } from 'vite';
import vue from '@vitejs/plugin-vue'
import path, { resolve } from 'path';



function pathResolve(dir: string){
  return resolve(process.cwd(), '.', dir);
}

// https://vite.dev/config/
export default ({command, mode}: ConfigEnv): UserConfig => {
  const root = process.cwd();
  const env = loadEnv(mode,root);

  const isBuild = command === 'build';
  return {
    base: '/wx/',
    root,
    resolve: {
      alias: [
        {
          find: 'vue-i18n',
          replacement: 'vue-i18n/dist/vue-i18n.cjs.js',
        },
        {
          find: /\/@\//,
          replacement: pathResolve('src') + '/',
        },
        {
          find: /\/#\//,
          replacement: pathResolve('types') + '/',
        },
      ],
    },
    server: {
      host: true,
      //https: false,
      port: 8080,
      //proxy: '',
    },
    build: {
      minify: 'esbuild',
      target: 'es2015',
      cssTarget: 'chrome80',
      terserOptions: {
      },
      reportCompressedSize: false,
      chunkSizeWarningLimit: 2000,
    },
    plugins: [vue()],
    optimizeDeps: {
      esbuildOptions: {
        target: 'es2020',
      },
      include: [

      ]
    }
  };
  
}
